<script>
function update_rp(r_id,p_url,p_name){
     new Ajax.Updater( 
        "centerDiv",
        "/system/user_manage/rp_update/"+r_id+"&"+p_url+"&"+p_name ,
        {  method: 'get',
          asynchronous: true,
          evalScripts: true,
          parameters: 'authenticity_token=' + window._token  
        }
      ); 
     }
</script>
<%= javascript_include_tag :defaults %>
<br /><br />
&nbsp;&nbsp;&nbsp;<a href="/system/user_manage/index">用户管理</a> >> 
角色权限管理<br />
  <h4>权限列表:</h4>
<div id="" style="margin-left : 15px;">
<table border="1"  width="850">
<% for role in @roles %> <tr>
<td width="120"><%=role.name %></td>
     <td width="880">
     <!--取出当前角色的所有权限集合-->
        <%   permissions= Permisssion.find(:all , :conditions => {:role_id => role.id}) -%>
      <!--取出当前系统的所有权限集合-->
        <%   for p in  Permisssion.find(:all , :conditions => {:role_id => 0}) -%>
        <!--两个权限集合比较-->
              <%   check=false
                for  permission  in  permissions
                  if  permission.url == p.url
                     check=true
                 end
               end  %>
            <input type="checkbox" name="<%=role.id%><%=p.url%>" onclick="update_rp(<%=role.id%>,'<%=p.url%>','<%=p.name%>');"
              <%  if  check==true %>
                checked=true
              <% end %>            
            ><%=p.name%></input>
       <% end %>
      </td> 
   </tr>
<%  end %>
</table>
<%=will_paginate(@roles ,:prev_label=>'上一页',:next_label=>'下一页',:separator=>" | ") %>
</div>
